﻿@using LanDBom.Models;
@using LanDBom.Resources
@{
    ViewBag.Title = "Detailed";
}
@section styles{
    <style>
        #td input {
            width: 50%;
        }

        #XJ_CP_a1 {
            display: none;
            width: 660px;
            height: 440px;
            background-color: #E8ECF6;
            position: fixed;
            left: 300px;
            top: 200px;
            z-index: 1000;
            border: 1px solid black;
        }

        .XJ_CPS_A1 {
            display: none;
            width: 660px;
            height: 500px;
            background-color: #E8ECF6;
            position: fixed;
            left: 300px;
            top: 100px;
            z-index: 1000;
            border: 1px solid black;
        }

        #XJ_CP_a2 {
            display: none;
            width: 660px;
            height: 440px;
            background-color: #E8ECF6;
            position: fixed;
            left: 300px;
            top: 200px;
            z-index: 1000;
            border: 1px solid black;
        }

        #XJ_CP_a1 > div {
            height: 100%;
            background-color: white;
            text-align: center;
        }

        #XJ_CP_WL_a1 {
            float: left;
            width: 300px;
        }

        #XJ_CP_GYS_a1 {
            float: right;
            width: 350px;
        }

        .shunf {
            margin-right: 30px;
            border: 1px solid;
            padding: 4px 5px;
            background-color: cornsilk;
        }
    </style>
}
<fieldset class="boun">
    <legend></legend>
    <div class="row bian">
        <label class="col-sm-3 breadcrumb-item ">步骤四：采购询价</label>
        <ul id="lisul" class="row col-sm-5">
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu">4</li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>
        </ul>
        <div class="col-sm-4">
            <div class="anzhu" style="text-align:right">
                <div class="col-4">
                    <button id="B_TH" style="width:90px">返回上一页</button>
                </div>
                <div class="col-2">
                    <button id="log_back">@Resource.String491</button>
                </div>
                <div class="col-2">
                    <button id="B_wanchen">完成</button>
                </div>
            </div>
        </div>
    </div>
</fieldset>
<div class="Zhuyags">
    <div class="col-2 nav-item" id="divjibeng" style="background-color:#fff">@Resource.String48</div>
    <div class="col-2 nav-item" id="divbeizhu">@Resource.String49</div>
    <div class="col-2 nav-item" id="divtuzhi">@Resource.String50</div>
    <div class="col-2 nav-item" id="divwlxx">物料信息</div>
    <div class="col-2 nav-item" id="divweituo" style="display:none">@Resource.String51</div>
</div>
<div>
    <div id="divsw1">
        <fieldset class="boun">
            <legend class="len">申请单信息</legend>
            <table id="BiaoTo" class="table-app">
                @foreach (var item in ViewBag.PRO_kehu as List<Applications>)
                {
                    <tr>
                        <td style="width:50%;">
                            @Html.Label(Resource.String429): @item.App_Kehu
                        </td>
                        <td style="width:50%;">
                            @Html.Label(Resource.String430):<label id="txtdan">@item.AP_bian</label>
                        </td>
                    </tr>
                    <tr>
                        <td>@Html.Label(Resource.String431): @item.App_qishi</td>
                        <td>@Html.Label(Resource.String432):@item.App_JTime</td>
                    </tr>
                    <tr>
                        <td>@Html.Label(Resource.String433): @item.APP_name</td>
                        <td>@Html.Label(Resource.String434): @item.App_lei</td>
                    </tr>
                    <tr>
                        <td>@Html.Label(Resource.String435): @item.APP_Zhong</td>
                        <td style="width:50%;">@Html.Label(Resource.String436): <lable id="leb"></lable></td>
                    </tr>
                    <tr>
                        <td>@Html.Label(Resource.String437): @item.App_dizhi</td>
                        <td>@Html.Label(Resource.String438): @item.App_sho</td>
                    </tr>
                    <tr style="display:none"> <td id="hisbdd">@item.AP_ren</td></tr>
                }
            </table>
        </fieldset>
    </div>
    <div id="divsw2" style="display:none">
        <div class="">
            <div id="bigbox1">
                <fieldset class="boun" id="boun" style="height:150px">
                    <legend class="len">@Resource.String558</legend>
                    <div id="RZ_gwzr" class="beizhugun">
                    </div>
                </fieldset>
            </div>
            <div>
                <fieldset class="boun" id="boun2">
                    <legend class="len">@Resource.String560</legend>
                    <div class="row">
                        <div class="col-2">@Resource.String563</div>
                        <div class="col-8"><textarea id="RZ_xznr" class="col-10" style="height:50px"></textarea></div>
                    </div>
                    <div style="text-align:right">
                        <button id="RZ_tjrz" class="col-2">@Resource.String564</button>
                    </div>
                </fieldset>
            </div>
        </div>
    </div>
    @*图纸备注*@
    <div id="divsw3" style="display:none">
        <div class="">
            <fieldset class="boun" id="boun3">
                <legend class="len">@Resource.String565</legend>
                <table style="width:100%;text-align:center" id="tab_wj">
                    <thead>
                        <tr style="background-color: #84acde">
                            <td>@Resource.String566</td>
                            <td>@Resource.String567</td>
                            <td>@Resource.String568</td>
                            <td>@Resource.String569</td>
                            <td>上传</td>
                        </tr>
                    </thead>
                    <tbody id="logfuj">
                    </tbody>
                </table>
            </fieldset>
        </div>
    </div>
    <div id="divsw4" style="display:none">
        <div>
            <fieldset class="boun">
                <legend class="len">物料信息</legend>
                <table id="Tenm" class="table table-sm">
                    <thead class="thead-light">
                        <tr>
                            <th scope="col" style="width:60px;">@Resource.String1286</th>
                            <th scope="col">@Resource.String1287</th>
                            <th scope="col">@Resource.String1288</th>
                            <th scope="col">@Resource.String1289</th>
                            <th>@Resource.String1290</th>
                            <th>@Resource.String1291</th>
                            <th scope="col">@Resource.String1292</th>
                            <th scope="col">@Resource.String1293</th>
                            <th scope="col">@Resource.String1294</th>
                            <th scope="col">@Resource.String1295</th>
                            <th scope="col">@Resource.String1296</th>
                        </tr>
                    </thead>
                    <tbody data-spy="scroll" id="BoTa">
                        @foreach (var item in ViewBag.fgh as List<BOMini>)
                        {
                            <tr>
                                <td></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_bian" readonly /></td>
                                <td>@item.BOM2_chen</td>
                                <td><input type="text" class="inwei" value="@item.BOM2_wuLiu" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_Lei" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_Ctime" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_Guige" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_Nian" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_Yong" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_fenzi" readonly /></td>
                                <td><input type="text" class="inwei" value="@item.BOM2_mioa" readonly /></td>
                            </tr>
                        }
                    </tbody>
                </table>
            </fieldset>
        </div>
    </div>
</div>
<div>
    <fieldset class="boun">
        <legend class="len">报价备注</legend>
        <div>
            <label for="CL_distance" class="col-lg-2 control-label">@Resource.String459</label>
            <input type="date" id="CG_LastTime" />
        </div>
        <div>
            <label for="CL_distance" class="col-lg-2 control-label">采购员询价备注</label>
            <textarea rows="5" class="col-lg-8" id="CG_JLLY"></textarea>
        </div>
    </fieldset>
</div>
<div id="XJ_CP_a1">
    <div class="Tuodong" style="background-color: #bacee9; height: 17px;"><span>点击这里拖动窗体</span></div>
    <div style="display: flex; height: 10%; border-bottom: 1px solid black; justify-content: space-between; align-items: center;"><span></span><span id="shian"></span><span id="XJMB_TC" class="shunf">退出</span></div>
    <div id="row" style="height:95%">
        <div id="XJ_CP_WL_a1" style="height:100%">
            <div id="XJ_CP_WL_a1_b1" style="height:90%;overflow:scroll"></div>
            <div><input type="text" name="jisnfdd" placeholder="@Resource.String461" style="display:none" /></div>
            <div id="XJ_CP_WL_a1_b2" style="height:10%" >提交供应商</div>
        </div>
        <div id="XJ_CP_GYS_a1" style="height:100%">
            <div id="wlname" style="height:10%;display:none">@Resource.String463</div>
            <div id="wlbianhao" style="display:none"></div>
            <idv id="LIaoH" style="display:none"></idv>
            <div>
                <div class="input-group mb-3">
                    <input type="text" class="form-control" placeholder="@Resource.String464" id="button_text" />
                    <div class="input-group-append">
                        <button class="btn-sm btn-outline-secondary" type="button" id="button_addon2"><i class="bi bi-search"></i></button>
                    </div>
                </div>
            </div>
            <div style="height: 77%; overflow: scroll" id="Gongyishang">
                @foreach (var item in ViewBag.efdm as List<Providers>)
                {
                    <div id="PR_ID" class="row">
                        <div class="col-1" style="line-height: 2;"><input type="checkbox" name="cb1" /></div>
                        <div class="col-10" id="PR_name" style="text-align:left">@item.PR_name</div>
                    </div>
                }
                @foreach (var item in ViewBag.lsitPR_name as List<Providers>)
                {
                    <div id="PR_ID" class="row">
                        <div class="col-1" style="line-height: 2;"><input type="checkbox" name="cb1" /></div>
                        <div class="col-10" id="PR_name" style="text-align:left">@item.PR_name</div>
                    </div>
                }
            </div>
            <div id="XJ_CP_TJGYS_a1" style="height:10%">@Resource.String465</div>
        </div>
    </div>

</div>
<div style="display:none" class="shenpijng XJ_CPS_A1">
    <table>
        <thead>
            <tr>
                <th>@Resource.String466</th>
                <th></th>
                <th>
                </th>
                <th>
                    <select id="SELsw">
                        <option value="1">@Resource.String467</option>
                        <option value="2">@Resource.String468</option>
                        <option value="3">@Resource.String469</option>
                    </select>
                </th>
            </tr>
            <tr>
                <td>@Resource.String470</td>
                <td>@Resource.String471</td>
                <td>@Resource.String472</td>
                <td>@Resource.String473</td>
            </tr>
        </thead>
        <tbody id="ajinfs">
            <tr>
                <td>
                    <input type="text" value="" class="form-control" id="shenpin" list="seleect_code" placeholder="@Resource.String474" />
                    <datalist id="seleect_code" class="form-control" style="display:none">
                    </datalist>
                </td>
                <td><input type="text" readonly class="form-control" name="Kjdns" /></td>
                <td><input type="date" class="form-control" id="dateC" /></td>
            </tr>
            <tr style="display:none">
                <td>
                    <input type="text" value="" class="form-control" id="shenpin1" list="seleect_code" placeholder="@Resource.String475" />
                    <datalist id="seleect_code" class="form-control" style="display:none">
                    </datalist>
                </td>
                <td><input type="text" readonly class="form-control" /></td>
                <td><input type="date" class="form-control" id="dateC1" /></td>
            </tr>
            <tr style="display:none">
                <td>
                    <input type="text" value="" class="form-control" id="shenpin2" list="seleect_code" placeholder="@Resource.String476" />
                    <datalist id="seleect_code" class="form-control" style="display:none">
                    </datalist>
                </td>
                <td><input type="text" readonly class="form-control" /></td>
                <td><input type="date" class="form-control" id="dateC2" /></td>
            </tr>
            <tr><td style="color:red">@Resource.String477</td></tr>
        </tbody>
    </table>
    <input type="button" id="buton1" value="@Resource.String478" />
    <input type="button" id="butonwes" value="@Resource.String479" />
</div>
<div id="XJ_CP_a2" style="overflow-y:scroll">
    <div class="Tuodong" style="width:50%"><span>点击这里拖动窗体</span></div> <div style="display: flex; justify-content: flex-end;" class="Tuodong"><span style="padding-right:10px" id="XJ_CP_a2_x2">@Resource.String480</span></div>
    <table class="table table-sm gun" style="background-color: #FFFFFF;">
        <thead class="thead-light">
            <tr>
                <th scope="col">@Resource.String481</th>
                <th scope="col">@Resource.String505</th>
                <th scope="col">@Resource.String482</th>
                <th scope="col">@Resource.String486</th>
                <th scope="col">@Resource.String487</th>
                <th scope="col">@Resource.String488</th>
            </tr>
        </thead>
        <tbody data-spy="scroll" id="XJ_Inf_Tbody">
        </tbody>
    </table>
</div>
<div>
    <div class="row">
        <div class="col-lg-2"><button type="button" style="width:100px" id="B_TJCGSR">@Resource.String490</button></div>
        <div class="col-lg-2"><button type="button" style="width:100px" id="B_CKYXJ">@Resource.String492</button></div>
        <div class="col-lg-2"><button type="button" style="width:100px" id="B_LSJG">@Resource.String493</button></div>
    </div>
    <table class="table table-sm gun">
        <thead class="thead-light">
            <tr>
                <th><input type="checkbox" id="ddmdd" /></th>
                <th><a>@Resource.String494</a></th>
                <th>@Resource.String495</th>
                <th>@Resource.String496</th>
                <th>@Resource.String101</th>
                <th>@Resource.String498</th>
                <th>@Resource.String499</th>
                <th>@Resource.String500</th>
                <th>@Resource.String104</th>
                <th>@Resource.String105</th>
            </tr>
        </thead>
        <tbody id="td_wlxx">
        </tbody>
    </table>
</div>
<div id="WT_dh_mb" class="BoHuiJM">
    <div id="WJ_ID" style="display:none"></div>
    <div class="se-lightblue"><p>驳回</p></div>
    <table class="table-sm table-light">
        <tr>
            <td>驳回节点：</td>
            <td>
                <select id="BHJD">
                    <option value="1">上一步</option>
                    <option value="2">报价发起</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>@Resource.String501：</td>
            <td id="WT_dhr"></td>
        </tr>
        <tr>
            <td>@Resource.String502</td>
            <td><textarea id="WT_dhly"></textarea></td>
        </tr>
    </table>
    <div class="dui se-lightblue">
        <button id="WT_qdbh">@Resource.String503</button>
        <button id="WT_qxbh">@Resource.String504</button>
    </div>
</div>

<div style="display:none" id="skndk">@(Session["appp_id"])</div>



@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <script>
        $(function () {
            $("#li5").css({ "color": "black", "background-color": "white" })
            //完成的方法
            if ($("#skndk").text() =="补充询价") {
                $("#B_wanchen").css({"display":"none"})
            }

            $(document).on("click", "#ddmdd", function () {
                if ($("#ddmdd").prop("checked") == true) {
                    console.log(1)
                    $(".xscc").prop("checked", true)
                }
                else {
                    $(".xscc").prop("checked", false)
                }
            })

            $(document).on("click", "#B_wanchen", function (e) {
                wanchengBOM()
            })
            function wanchengBOM() {
                JLBOmin = 0;
                $(".HJ_CP_ban_b2").each(function (i, item) {
                    $(item).parent().parent().css({ "background-color": "none" })
                    $.ajax({
                        url: '/Procure/Modify_BOM_WANC',
                        type: 'GET',
                        data: { "Hid": $(item).val() },
                        success: function (data) {
                            JLBOmin++;
                            console.log(JLBOmin)
                            wancheng3_4(JLBOmin)
                            if (data != "1") {
                                $(item).parent().parent().css({ "background-color": "#dc3545" })
                            }
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                })
            }
            function wancheng3_4(ij) {
                var JNFJD = $("#td_wlxx tr").length
                if (ij == JNFJD) {
                    var bian = $("#txtdan").text()
                    $.ajax({
                        url: '/Procure/Modify_App_bu_g_x',
                        type: 'GET',
                        data: { "bian": bian },
                        success: function (data) {
                            alert(data)
                            if (data != "") {
                                window.location.href = "/Procure/Overview"
                            }
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }
            }
            //驳回的方法
            function Rejected_plan(GNH) {
                var de_id = $("#txtdan").text()
                var bhly = $("#WT_dhly").val()
                var shr = $("#WT_dhr").text()
                if (bhly == "") {
                    alert("请输入驳回理由,此次驳回会直接驳回至BOM重置")
                }
                else {
                    var BZJG = [];
                    BZJG.push({
                        AP_bian: de_id,
                        APP_shr: shr,
                        APP_liy: bhly,
                        App_bu: GNH,
                        App_zhuang: "驳回"
                    })
                    console.log("共" + BZJG.length + "数据");
                    console.log(BZJG);
                    $.ajax({
                        url: "/Procure/Modify_INF_zhuang3",
                        type: 'POST',
                        data: JSON.stringify(BZJG),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            var regex = /\-?\d+(\.\d+)?/g;
                            var matches = text.match(regex);
                            if (matches == null) {
                                alert("驳回失败！")
                            } else {
                                var mbr = $("#hisbdd").text()
                                var name = $("#Login_N").text()
                                var BZJG = [];
                                BZJG.push({
                                    Fr_fl: "物料询价",//待处理模块
                                    De_tiji: "物料询价被驳回",//待处理内容
                                    Cl_juli: mbr,//接收人
                                    Nd_jiage: name,//发起人
                                    Fr_zhuang: "待处理"//装态
                                })
                                console.log("共" + BZJG.length + "数据");
                                console.log(BZJG);
                                $.ajax({
                                    url: "/Contracts/Addfr",
                                    type: 'POST',
                                    data: JSON.stringify(BZJG),
                                    contentType: "application/json;charset=utf-8",
                                    dataType: "json",
                                    success: function (text) {
                                        var regex = /\-?\d+(\.\d+)?/g;
                                        var matches = text.match(regex);
                                        if (matches == null) {
                                            alert("已驳回至对应人")
                                        } else {
                                            alert("已驳回至对应人")
                                            location.reload(true)
                                            location.href = "/Procure/Overview"
                                        }

                                    },
                                    error: function (text) {
                                        alert("系统错误" + text);
                                    }
                                })
                            }
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })
                }
            }
           
            //点击驳回到业务
            $(document).on("click", "#WT_qdbh", function () {
                var shunf = $("#BHJD").val()
                if (shunf == 1) {
                    Rejected_plan(2)
                } else {
                    Rejected_plan(1)
                }
            })


            //点击打开驳回面板
            $(document).on("click", "#log_back", function (e) {
                var id = $(e.target).parent().parent().children().first().text()
                $("#WJ_ID").text(id)
                $("#WT_dh_mb").css({ "display": "block" })
                var num = $("#Login_N").text()
                $("#WT_dhr").text(num)
            })
            //点击关闭驳回面板
            $(document).on("click", "#WT_qxbh", function (e) {
                $("#WT_dh_mb").css({ "display": "none" })
                $("#WT_dhly").val("")
                $("#WT_dhr").text("")
                $("#WJ_ID").text("")
            })
            //时间
            sjiQxnf()
            function sjiQxnf() {
                var now = new Date($.now());
                //获取当前年月日
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var qishi_time2 = year + "/" + month + "/" + date
                //$("#shenpin").parent().next().children().val(qishi_time2)
                $("#ajinfs tr td:nth-child(2)").each(function (w, PLk) {
                    $(PLk).children().val(qishi_time2)
                })
            }
            ////选择审批人数
            //$(document).on("change", "#SELsw", function () {
            //    $(document).on("change", "#SELsw", function () {
            //        var AS1 = $(this).val()
            //        console.log(AS1)
            //        if (AS1 == "1") {
            //            $("#shenpin").parent().parent().show()
            //            $("#shenpin1,#shenpin2").parent().parent().hide()
            //            $("#shenpin1,#shenpin2").text()
            //        }
            //        if (AS1 == "2") {
            //            $("#shenpin,#shenpin1").parent().parent().show()
            //            $("#shenpin2").parent().parent().hide()
            //            $("#shenpin2").text()
            //        }
            //        if (AS1 == "3") {
            //            $("#shenpin,#shenpin1,#shenpin2").parent().parent().show()

            //        }
            //    })
            //    sjiQxnf()
            //})
            //筛选
            $(document).on("click","#button_addon2",function () {
                var shufnnf = $("#button_text").val()
                GysLieB(shufnnf)
            })
            //点击修改要询价的物料
            $(document).on("click", ".cbk", function (e) {
                $("#wlname").text($(e.target).next().text())
                $("#wlbianhao").text($(e.target).next().next().text())
                $("#LIaoH").text($(e.target).next().next().next().text())
                $("wlname").css({ "background-color": "coral", "color": "white" })
                GysLieB($("#button_text").text())
            })

            function GysLieB(shufnnf) {
                var LiaoH = $("#LIaoH").text()
                if (LiaoH == "") {
                    alert("请选择物料！")
                } else {
                    $.ajax({
                        url: '/Procure/Detailed',
                        type: 'GET',
                        data: { "Button_te": shufnnf, "state": 7, "LiaoH": LiaoH },
                        success: function (data) {
                            createRow_GONGisus(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    $.ajax({
                        url: '/Procure/Detailed',
                        type: 'GET',
                        data: { "Button_te": shufnnf, "state": 2},
                        success: function (data) {
                            createRow_GONGisus2(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }

            }
            function createRow_GONGisus(data) {
                $("#Gongyishang div").remove()
                $.each(data, function (i, item) {
                    var $div = $(`<div id="PR_ID" class="row">
                                <div class="col-1"style="line-height: 2;"><input type="checkbox" name="cb1" /></div>
                                <div class="col-10" id="PR_name" style="text-align:left">${item.PR_name}</div>
                            </div>`);
                    $("#Gongyishang").append($div)
                })
            }
            function createRow_GONGisus2(data) {
                $.each(data, function (i, item) {
                    var $div = $(`<div id="PR_ID" class="row">
                    <div class="col-1"style="line-height: 2;"><input type="checkbox" name="cb1" /></div>
                    <div class="col-10" id="PR_name" style="text-align:left">${item.PR_name}</div>
                </div>`);
                    $("#Gongyishang").append($div)
                })
            }
            //返回事件
            $("#B_TH").click(function () {
                window.location.href = "/Procure/Overview";
            })
            //获取申请单编号
            var APP_bian = $("#txtdan").text()
            console.log(APP_bian)
            //根据申请单号搜索BOM
            function ssBOM() {
                $.ajax({
                    url: '/Procure/Detailed',
                    type: 'GET',
                    data: { "APP_bian": APP_bian, "state": 4 },
                    success: function (data) {
                        createRow_BOM(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            $(document).ready(function () {
                Sheq()
                ssBOM()
            })
            //搜索申请单信息
            function Sheq() {
                $.ajax({
                    url: '/Procure/Detailed',
                    type: 'GET',
                    data: { "APP_bian": APP_bian, "state": 6 },
                    success: function (data) {
                        AddValue(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            //加载申请单信息
            function AddValue(data) {
                $.each(data, function (i, item) {
                    $('#txtname').val(item.App_Kehu),
                        $('#txtqishi').val(item.App_qishi),
                        $('#txtjeishu').val(item.App_JTime),
                        $('#txtxiangmu').val(item.APP_name),
                        $('#txtzhongduan').val(item.APP_Zhong),
                        $('#txtsho').val(item.App_dizhi),
                        $('#txtjuli').val(item.App_ju),
                        $('#txtmudi').val(item.App_mu),
                        $('#txtfu').val(item.App_sho),
                        $('#beizhu').val(item.App_bei),
                        $('#tuzhi').val(item.App_tuzhi)
                })
            }
            //点击使用历史价格
            $(document).on("click", "#B_LSJG", function () {
                var check = $("input[type=checkbox]:checked").parent().parent().length;
                if (check < 0) {
                    alert(0);
                }
                else {
                    $("input[type=checkbox]:checked").parent().parent().each(function (index, obj) {
                        var x = $(obj).children().eq(6).children().val()
                        if (x == "0") {
                            console.log("历史价格为空")
                        }
                        else {
                            $(obj).remove()
                        }
                    })
                }
            })
            //加载BOM信息
            function createRow_BOM(data) {
                $('#td_wlxx tr').remove()
                if ($("#Login_sf").text() == "业务发展部经理" || $("#Login_sf").text() == "采购主管") {
                    $.each(data, function (i, item) {
                        var temp7 = item.BOM2_Sone;
                            temp7=  temp7 == "1" ? "纸质" : temp7 == "2" ? "木质" : temp7 == "3" ? "塑料" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7;
                        var $xxx = $(`
                                        <tr>
                                            <td><input type="checkbox" name="HJ_CP_name" class="xscc"/></td>
                                            <td><input readonly="readonly" name="CG_WLM" value="${item.BOM2_wuLiu}" id="HJ_CP_WL_b1" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_CC" value="${item.BOM2_chen}" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_WLBH" value="${item.BOM2_liao}" style="width:100px" id="HJ_CP_LH_b1"/></td>
                                            <td><input readonly="readonly" value="${item.BOM2_Guige}" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_MS" value="${item.BOM2_mioa}" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_MS" value="${item.Nd_jiage}" style="width:100px"/></td>
                                            <td><input readonly="readonly" style="width:100px" value="${item.BOM2_Lei}"/></td>
                                            <td><input readonly="readonly" style="width:100px" value="${temp7}"/></td>
                                            <td><input readonly="readonly" style="width:100px" value="${item.BOM2_ST}"/></td>
                                            <td style="display:none"><input readonly="readonly" id="HJ_CP_ban_b1"style="width:100px" value="${item.BOM2_id}" class="HJ_CP_ban_b2"/></td>
                                        </tr>
                                    `);
                        $('#td_wlxx').append($xxx);

                    })
                }
                else if ($("#Login_sf").text() == "采购员") {
                    $.ajax({
                        url: '/Procure/Detailed',
                        type: 'GET',
                        data: { "id": $("#Login_name").text(), "state": 1 },
                        success: function (date) {
                            $.each(date, function (i, obj) {
                                $.each(data, function (i, item) {
                                    var temp7 = item.BOM2_Sone;
                                    temp7 = temp7 == "1" ? "纸质" : temp7 == "2" ? "木质" : temp7 == "3" ? "塑料" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7;
                                    var $xxx = $(`
                                                    <tr>
                                                        <td><input type="checkbox" name="HJ_CP_name"/></td>
                                            <td><input readonly="readonly" name="CG_WLM" value="${item.BOM2_wuLiu}" id="HJ_CP_WL_b1" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_CC" value="${item.BOM2_chen}" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_WLBH" value="${item.BOM2_liao}" style="width:100px" id="HJ_CP_LH_b1"/></td>
                                            <td><input readonly="readonly" value="${item.BOM2_Guige}" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_MS" value="${item.BOM2_mioa}" style="width:100px"/></td>
                                            <td><input readonly="readonly" name="CG_MS" value="${item.Nd_jiage}" style="width:100px"/></td>
                                            <td><input readonly="readonly" style="width:100px" value="${item.BOM2_Lei}"/></td>
                                            <td><input readonly="readonly" style="width:100px" value="${temp7}"/></td>
                                            <td><input readonly="readonly" style="width:100px" value="${item.BOM2_ST}"/></td>
                                            <td style="display:none"><input readonly="readonly" id="HJ_CP_ban_b1"style="width:100px" value="${item.BOM2_id}" class="HJ_CP_ban_b2"/></td>
                                                    </tr>
                                    `);
                                    console.log(obj.du_name, item.BOM2_ST)
                                    if (obj.du_name == item.BOM2_ST) {

                                        $('#td_wlxx').append($xxx);
                                    }
                                })
                            })
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }
            }
            //显示已询价信息
            function Display_inquiry() {
                $.ajax({
                    url: '/Procure/Overview',
                    type: 'GET',
                    data: { "App_bian": APP_bian, "state": 5 },
                    success: function (data) {
                        createTR(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            //答应询价信息
            function createTR(data) {
                $('#XJ_Inf_Tbody tr').remove();
                $.each(data, function (i, item) {
                    var index=0
                    var $tr = $(`
                        <tr class="unf_oo">
                            <td id="Inf_id">${item.Inf_id}</td>
                            <td>${item.Inf_shen}</td>
                            <td id="gongnn33">${item.Inf_wu}</td>
                            <td id="gongnn">${item.Inf_gong}</td>
                            <td>${item.Inf_huiTime}</td>
                            <td>${item.Inf_zhuang}</td>
                        </tr>

                    `);
                    $(".unf_oo").each(function (i, obj) {

                        var name = $("td[id=gongnn33]", obj).text()
                        var gong = $("td[id=gongnn]", obj).text()
                        console.log(name, gong,1)
                        console.log(item.Inf_wu, item.Inf_gong,2)
                        if (name == item.Inf_wu && gong == item.Inf_gong) {
                            index++
                            console.log("btj")
                        }
                    })
                    if (index==0) {
                        $('#XJ_Inf_Tbody').append($tr);
                    }
                })
            }
            //加载选中的物料来选择供应商
            function inquiry() {
                $("#XJ_CP_WL_a1_b1 div").remove()
                $("input[name=HJ_CP_name]:checked").parent().parent().each(function (index, obj) {
                    var num = $("input[id='HJ_CP_WL_b1']", obj).val()
                    var lh = $("input[id='HJ_CP_LH_b1']", obj).val()
                    var lh12 = $("input[id='HJ_CP_ban_b1']", obj).val()
                    var $div =
                        $(`
                            <div id="wlwlming_p" style="background-color:gray">
                                  <input type="checkbox" name="${num}" class="cbk"/>
                                  <div id="wlwlming">${num}</div>
                                  <div style="display:none">${lh}</div>
                                  <div style="display:none">${lh12}</div>
                                  <div style="background-color: darkgrey;">
                                      <ul id="${lh}">
                                      </ul>
                                  </div>
                            </div>
                         `);
                    $("#XJ_CP_WL_a1_b1").append($div)
                })
            }

            window.onload = function () {
                var today = new Date();
                var simmo = today.getFullYear() + '/' + (today.getMonth() + 1) + '/' + today.getDate()
                $("#CG_LastTime").val(simmo)
                //dateInput.value = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
                console.log(simmo)
            }
            function Add_supplier() {
                $("input[name=cb1]:checked").each(function (i, obj) {
                    var gysm = $(obj).parent().next().text()//供应商名
                    var wlm = $(obj).parent().parent().parent().parent().children().first().text()//物料名
                    var lh = $(obj).parent().parent().parent().parent().children().first().next().text()//料号
                    var $li = $(`<li id="${lh}">${gysm}</li>`)
                    $("input[class=cbk]:checked").each(function (i, a) {
                        var inde = 0
                        $.each($(a).parent().children().eq(4).children().first().get(), function (j, index) {
                            if ($(index).children().text() == "") {
                                console.log("无")
                                $(a).parent().children().eq(4).children().first().append($li)
                            }
                            else {
                                $.each($(index).children().get(), function (x, num) {
                                    if ($(num).text() == gysm) {
                                        console.log("不添加" + gysm)
                                        inde = inde + 1
                                    }
                                })
                            }
                        })
                        console.log(inde)
                        if (inde == 0) {
                            $(a).parent().children().eq(4).children().first().append($li)
                            console.log("添加成功" + gysm)
                        }

                    })
                })




                //$("input[name='cb1']:checked").each(function (i, obj) {


                //    $("div[id='wlwlming_p']").each(function (i, a) {
                //        var inde = 0
                //        if ($(a).children().eq(0).text() == wlm) {
                //            $.each($(a).children().eq(3).children().first().get(), function (j, index) {
                //                if ($(index).children().text() == "") {
                //                    console.log("无")
                //                    $(a).children().eq(3).children().first().append($li)
                //                }
                //                else {
                //                    $.each($(index).children().get(), function (x, num) {
                //                        if ($(num).text() == gysm) {
                //                            console.log("不添加" + gysm)
                //                            inde = inde + 1
                //                        }
                //                    })
                //                }
                //            })
                //            console.log(inde)
                //            if (inde == 0) {
                //                $(a).children().eq(3).children().first().append($li)
                //                console.log("添加成功" + gysm)
                //            }
                //        }
                //    })
                //})

            }
            $(document).on("click", "div[id='wlwlming_p'] li", function (e) {
                $(e.target).remove()
            })
            //关闭询价面板
            $(document).on("click", "#XJMB_TC", function () {
                $("#XJ_CP_a1").css({ "display": "none" })
            })
            //提交选择的供应商询价
            $(document).on("click", "#XJ_CP_WL_a1_b2", function () {
                var sjinfko = 0;
                $("div[id=wlwlming_p]").each(function (i, item) {
                    var SL = 0;
                    SL = $(item).find('li').length
                    if (SL < 3) {
                        $("#shian").text(name + "物料询价供应商不满三个请填写理由");
                        sjinfko++;
                    }
                })
                var SWM = $("input[name='jisnfdd']").val()
                if (sjinfko == 0 || SWM != "") {
                    addinf()
                } else if (sjinfko > 0) {
                    $("input[name='jisnfdd']").show()
                }
            })
            $(document).on("click", "#butonwes", function () {
                $(".shenpijng").hide()
            })

            function addinf() {
                var bianhao = $("#txtdan").text()
                var x = 0
                var CG_XX = [];

                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var hours = (now.getHours()).toString()
                var minutes = (now.getMinutes()).toString()
                //组合当前日期
                var sqrq = year + "/" + month + "/" + date

                $.ajax({
                    url: '/Procure/Detailed',
                    type: 'GET',
                    data: { "APP_bian": bianhao, "state": 3 },
                    success: function (data) {
                        x = data
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
                $("input[class=cbk]:checked").parent().each(function (i, item) {
                    var SL = 0;
                    var name = $("div[id=wlwlming]", item).text()
                    var lh = $("div[id=wlwlming]", item).next().text()
                    var lhwda = $("div[id=wlwlming]", item).next().next().text() * 1
                    $(item).children().children().children().each(function (o, obj) {
                        SL += 1;//obj.id == lh
                        if (true) {
                            CG_XX.push({
                                Inf_wu: name,
                                Inf_gong: $(obj).text(),
                                Inf_shen: APP_bian,
                                Inf_huiTime: $("#CG_LastTime").val(),
                                Inf_bei: $("#CG_JLLY").val(),
                                Inf_zhuang: "等待中",
                                INF_qi: x,
                                Inf_ftime: sqrq,
                                BOM2_id: lhwda,
                                Inf_liao: lh
                            })
                        }
                        //判断询价供应商是否符合要求
                    })
                })
                console.log(CG_XX.length+"sss")
                if (CG_XX.length > 0) {
                    $.ajax({
                        url: "/Procure/AddCGXX",
                        type: 'POST',
                        data: JSON.stringify(CG_XX),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text2) {
                            $.ajax({
                                url: "/Procure/Detailed",
                                type: 'POST',
                                data: { "state": 10, "APP_bian": APP_bian, "yonghu": $("input[name='jisnfdd']").val() },
                                success: function (text) {
                                    if (text2 == 0) {
                                        alert("提交成功")
                                    }
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })
                }
                else {
                    alert("请先选择需要提交的物料")
                }
            }


            //提交供应商
            $(document).on("click", "#XJ_CP_TJGYS_a1", function () {
                $("input[class=cbk]:checked").each(function (i, obj) {
                    Add_supplier()
                })

            })

            //打开供应商选择面板
            $(document).on("click", "#B_TJCGSR", function () {
                //判断恢复日期是否添加
                var dhifn = $("#CG_LastTime").val()
                console.log(dhifn)
                if (dhifn == "") {
                    alert("请选择回复日期")
                } else {
                    $("#XJ_CP_a1").css({ "display": "block" });
                   inquiry()
                }

            })
            $(document).on("click", "#B_CKYXJ", function () {
                $("#XJ_CP_a2").css({ "display": "block" })
                Display_inquiry()
            })
            $(document).on("click", "#XJ_CP_a2_x2", function () {
                $("#XJ_CP_a1").css({ "display": "none" });
            })
            $(document).on("click", "#XJ_CP_a2_x2", function () {
                $("#XJ_CP_a2").css({ "display": "none" })
            })


        })
        //审批人输入事件
        $(function () {
            $(document).on("keyup", "#shenpin", function () {
                var shun = $(this).val();
                var liongj = $("#Login_N").text()
                $.ajax({
                    url: '/Procure/Detailed',
                    type: 'POST',
                    data: { "Name": shun, "yonghu": liongj, "state": 9 },
                    success: function (e) {
                        createSel(e);
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            })
            function createSel(e) {
                $("#seleect_code option").remove();
                $.each(e, function (i, item) {
                    var $tr = (`<option value="${item.DE_nae}">`);
                    $("#seleect_code").append($tr);
                })
            }
        })
        //权限不同页面不同

        $(function () {
            //gettuz()//搜索图纸信息
            gettbz()//搜索备注信息
            //点击切换基础信息，备注信息，图纸沟通
            $(function () {
                $("#divjibeng").click(function (e) {
                    $("#divsw1").css({ "display": "block" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divbeizhu").click(function (e) {
                    $("#divsw2").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divtuzhi").click(function (e) {
                    $("#divsw3").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divwlxx").click(function (e) {
                    $("#divsw4").css({ "display": "block" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw2").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
            })
            //获取图纸信息

            //获取备注信息
            function gettbz() {
                var kan = $("#txtdan").text();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 4 },
                    success: function (sjik) {
                        $("#RZ_gwzr div").remove();
                        $.each(sjik, function (i, item) {
                            var $tr = $(`  <div>
                                    <div>
                                        <span style="color:red">${item.B_BR}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>${item.B_Date}</span>
                                    </div>
                                    <div style="border-bottom:1px solid #808080">
                                        ${item.B_bei}
                                    </div>
                                </div>`);
                            $("#RZ_gwzr").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
             //获取图纸信息
            Load_design_table()
            //获取图纸信息
            function Load_design_table() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 3, "App_ban": $('#txtdan').text()},
                    success: function (path) {
                        createFJ(path)
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            function createFJ(fgggh) {
                $("#logfuj tr").remove();
                $("#div3__tb tr").remove();
                var ind1 = 1
                var ind2 = 1
                var temp=0
                $.each(fgggh, function (i, item) {
                    var x = item.De_dizhi
                    if (item.DE_lei == "图纸") {
                        var $tr = (`
                        <tr class="log_tr">
                            <td style="display:none">${item.DE_id}</td>
                            <td>${ind1}</td>
                            <td>${item.DE_TZname}</td>
                            <td>${item.bom_id}</td>
                            <td>${item.De_shijian}</td>
                            <td>${item.De_ren}</td>
                            <td>
                                <input type="number" readonly="readonly" value="${item.DE_Slong}" style="width:60px;height:30px"/>
                            </td>
                            <td><a href="#" id="log_SC">删除</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">@Resource.String582</a></td>
                        </tr>`);
                        $("#div3__tb").append($tr);
                        ind1++
                        temp += item.DE_Slong*1
                    }
                    else {
                        var $tr = (`
                        <tr class="log_tr">
                            <td style="display:none">${item.DE_id}</td>
                            <td>${ind2}</td>
                            <td>${item.De_dizhi}</td>
                            <td>${item.De_shijian}</td>
                            <td>${item.De_ren}</td>
                            <td><a href="/Contracts/Download_file?path=${x}" id="log_SZ">@Resource.String582</a></td>
                        </tr>`);
                        $("#logfuj").append($tr);
                        ind2++
                    }
                })
                $("#SJ_ZYS").text(temp)
            }
            //日志写入数据库
            $(document).on("click", "#RZ_tjrz", function () {
                if ($('#RZ_xznr').val() != "") {
                    var now = new Date($.now());
                    var year = (now.getFullYear()).toString();
                    var month = (now.getMonth() + 1).toString();
                    var date = (now.getDate()).toString();
                    var hours = (now.getHours()).toString()
                    var minutes = (now.getMinutes()).toString()

                    //组合当前日期
                    var sqrq = year + "/" + month + "/" + date + " " + hours + ":" + minutes
                    var rzxx = {
                        B_Bian: $("#txtdan").text(),
                        B_BR: $('#Login_N').text(),
                        B_Date: sqrq,
                        B_bei: $('#RZ_xznr').val(),

                    };
                    console.log(rzxx)
                    $.ajax({
                        url: "/Contracts/AddLogs",
                        type: "POST",
                        data: rzxx,
                        success: function (data) {
                            alert(data)
                            $('#RZ_xznr').val("")
                            gettbz()
                        },
                        error: function (data) {
                            alert("erroer");
                        },
                    })
                }
            })

        })

    </script>
}